class Trie:

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.nodes = {}


    def insert(self, word: str) -> None:
        """
        Inserts a word into the trie.
        """
        nodes = self.nodes
        for s in word:
            if s in nodes:
                nodes = nodes[s]
            else:
                new_dict = {}
                nodes[s] = new_dict
                nodes = new_dict
        else:
            nodes["end"] = True


    def search(self, word: str) -> bool:
        """
        Returns if the word is in the trie.
        """
        nodes = self.nodes
        for s in word:
            if s in nodes:
                nodes = nodes[s]
            else:
                return False
        return "end" in nodes

    def startsWith(self, prefix: str) -> bool:
        """
        Returns if there is any word in the trie that starts with the given prefix.
        """

        nodes = self.nodes
        for s in prefix:
            if s in nodes:
                nodes = nodes[s]
            else:
                return False
        return True


if __name__ == "__main__":
    trie = Trie()
    trie.insert("flower")
    trie.insert("flow")
    trie.insert("flzw")
    assert trie.search("flow")
    assert trie.search("flow1") == False
    assert trie.search("flo") == False
    assert trie.startsWith("flo")
    print(trie.nodes)
    print(trie.nodes["f"])